/*
 * @LastEditTime: 2023-11-07 10:29:47
 * @FilePath: \bdcar-net\vite\plugins\compression.js 
 */
import compression from 'vite-plugin-compression'

export default function createCompression(env) {
    const { VITE_BUILD_COMPRESS } = env
    const plugin = []
    if (VITE_BUILD_COMPRESS) {
        const compressList = VITE_BUILD_COMPRESS.split(',')
        if (compressList.includes('gzip')) {
            plugin.push(
                compression({
                    ext: '.gz',
                    deleteOriginFile: false,
                    filter: (source) => {
                        // 排除特定文件
                        return !source.endsWith('GlobalSetting.js');
                    },
                })
            )
        }
        if (compressList.includes('brotli')) {
            plugin.push(
                compression({
                    ext: '.br',
                    algorithm: 'brotliCompress',
                    deleteOriginFile: false,
                })
            )
        }
    }
    return plugin
}
